/*
 * Copyright 2018 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.admin.config;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;

import com.lap.scd.commons.domain.BaseDO;
import com.lap.scp.admin.utils.UserUtils;

/**
 * <pre>
 *	操作人aop，目前只对edit,add进行拦截，并赋值到createdBy,lastUpdatedBy
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018年2月21日 下午3:16:19
 * @since 1.0
 */
@Aspect
@Configuration
public class OperationConfig {

	@Pointcut("execution(public * com.lap.scp.*.controller.*Controller.edit*(..))")
	public void edit() {
	}

	@Pointcut("execution(public * com.lap.scp.*.controller.*Controller.add*(..))")
	public void add() {
	}

	@Pointcut("execution(public * com.lap.scp.*.controller.*Controller.update*(..))")
	public void update() {
	}

	@Before("add() or edit() or update()")
	public void before(JoinPoint joinPoint) {
		Object[] args = joinPoint.getArgs();
		if (args != null && args.length > 0) {
			for (Object obj : args) {
				if (obj != null && obj instanceof BaseDO) {
					BaseDO modelDO = (BaseDO) obj;
					UserUtils.setUsername(modelDO);
				}
			}
		}
	}

}
